package com.whfc.ms.api.fmam.service.impl;

import com.whfc.common.result.ListData;
import com.whfc.common.result.PageData;
import com.whfc.fmam.entity.dto.FmamWarehouseDTO;
import com.whfc.fmam.entity.qo.WarehouseAddQO;
import com.whfc.fmam.entity.qo.WarehouseEditQO;
import com.whfc.fmam.service.FmamWarehouseService;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.fmam.cache.LocalSysDeptService;
import com.whfc.ms.api.fmam.service.WarehouseService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: ；likang
 * @Description:
 * @Date:Create：in 2019/11/14 14:33
 * @Version：1.0
 */
@Service
public class WarehouseServiceImpl implements WarehouseService {

    @DubboReference(interfaceClass = FmamWarehouseService.class, version = "1.0.0")
    private FmamWarehouseService famawarehouseService;

    @Autowired
    private LocalSysDeptService localSysDeptService;


    @Override
    public PageData<FmamWarehouseDTO> listFmamWarehouseDTO(SysUser user, Integer pageNum, Integer pageSize, Integer deptId) {
        PageData<FmamWarehouseDTO> fmamWarehouseDTOPageData = famawarehouseService.listFmamWarehouseDTO(pageNum, pageSize, deptId);
        List<FmamWarehouseDTO> list = fmamWarehouseDTOPageData.getList();
        for (FmamWarehouseDTO fmamWarehouseDTO : list) {
            //添加组织机构名称
            Integer deptId1 = fmamWarehouseDTO.getDeptId();
            String name = localSysDeptService.getDeptName(deptId1);

            fmamWarehouseDTO.setDeptName(name);
        }
        return fmamWarehouseDTOPageData;
    }

    @Override
    public ListData<FmamWarehouseDTO> listFmamWarehouseDTO(Integer deptId) {
        List<FmamWarehouseDTO> list = famawarehouseService.listFmamWarehouseDTO(deptId);
        return new ListData<>(list);
    }

    @Override
    public void addWarehouse(WarehouseAddQO warehouseAddQO) {
        famawarehouseService.addWarehouse(warehouseAddQO);
    }

    @Override
    public void editWarehouse(WarehouseEditQO warehouseEditQO) {
        famawarehouseService.editWarehouse(warehouseEditQO);
    }

    @Override
    public void enableWarehouse(Integer id) {
        famawarehouseService.enableWarehouse(id);
    }

    @Override
    public void disableWarehouse(Integer id) {
        famawarehouseService.disableWarehouse(id);
    }

    @Override
    public void delWarehouse(Integer id) {
        famawarehouseService.deleteWarehouse(id);
    }
}
